<template>
  <div id="app">
   <h1>{{$store.state.counter}}</h1>
   <button @click="handleAdd">加</button>
   <button @click="handleSub">减</button>
   <button @click="handleAsyncAdd">异步加</button>
    <h1>{{isOddOrEven}}</h1>
    <h1>{{localGetter}}</h1>
    <!-- <h1>{{$store.getters.isOddOrEven}}</h1> -->
  </div>
</template>

<script>
import {ADD,SUB} from "./mutations-type"
// 引入辅助函数
import {mapGetters} from "vuex"
export default {
  name: 'App',
  components: {
  },
  computed:{
    isOddOrEven: function(){
      return this.$store.state.counter %2===0 ? "偶数" : "奇数"
    }
  },
    handleSub: function(){
      this.$store.commit({
        type: SUB,
        payload:{
          step:-1
        }
      })
    },
    handleAsyncAdd: function(){
      this.$store.dispatch("asyncAdd",1)
    },
  }
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
